import { History } from "history";
import { Dispatch } from "redux";
import { Reducers } from "../../../../../App";
import { IColumn } from "../../interfaces";
import { getTableDatasourceAct, setTableFilterAct } from "../../store/actions";
import { IReducerState_TableFilter } from "../../store/reducer";

interface IPropsState {
  datasource: { total:number, list:Array<IColumn> };
  loading: boolean;
  filter: IReducerState_TableFilter;
}

interface IPropsDispatch {
  getDatasource: (filter: IReducerState_TableFilter) => void;
  setFilter: (filter: IReducerState_TableFilter) => void;
}

interface IExtra {
  history: History;
}

export type TProps = IPropsState & IPropsDispatch & IExtra;

export const mapStateToProps = (state: Reducers): IPropsState => {
  const reducer = state.manageOrderReducer;
  return {
    datasource: reducer.table_datasource,
    loading: reducer.table_loading,
    filter: reducer.table_filter
  };
};

export const mapDispatchToProps = (dispatch: Dispatch): IPropsDispatch => ({
  getDatasource(filter: IReducerState_TableFilter) {
    const action: any = getTableDatasourceAct(filter);
    dispatch(action);
  },
  setFilter(filter: IReducerState_TableFilter) {
    const action = setTableFilterAct(filter);
    dispatch(action);
  }
});
